<template>
	<view class="message-notice-wrapper">
		<div class="list-wrapper">
			<view class="more-search">
				<u-search placeholder="搜索" class="search-input" @change="openSearch" :show-action="false">
				</u-search>
			</view>
			<!-- <view class="chat_list_wraper" > -->
			<scroll-view scroll-y="true" :class="
			  'chat_list_wraper ' + (gotop ? (isIPX ? 'goTopX' : 'goTop') : 'goback')
			" :style="'padding-bottom: ' + (isIPX ? '270rpx' : '226rpx')">
				<view class="search_input" v-if="search_chats">
					<view>
						<icon type="search" size="12"></icon>
						<input placeholder="搜索" placeholder-style="color:#9B9B9B;line-height:21px;font-size:15px;"
							auto-focus confirm-type="search" type="text" @confirm="onSearch" @input="onInput"
							:value="input_code" />
						<icon type="clear" size="12" @tap.stop="clearInput" v-if="show_clear"></icon>
					</view>
					<text @tap="cancel">取消</text>
				</view>
				<div class="item-wrapper" @click='toNoticeList'>
					<div class='systemInform'>
						<image class="image" src="/static/menu-notice.png" mode="aspectFill"></image>
						<div class='text'>
							<div class="name">系统通知</div>
							<div class="newInformation">您有新的服务消息通知</div>
						</div>
					</div>
				<!-- 	<div class='item'>
						<div class="time">07:23</div>
							<div class="itemNumber">11000</div>
					</div> -->
				</div>
				<view v-for="(item, index) in arrNew||arr" :key="index" class="chat_list" :data-item="item"
					@tap.stop="del_chat" @longpress="longpress">
					<swipe-delete>
						<view class="tap_mask" @tap.stop="into_chatRoom" :data-item="item">
							<!-- 消息列表 -->
							<view class="list_box">
								<view class="list_left" :data-username="item.username">
									<view class="list_pic">
										<view class="em-msgNum"
											v-if="item.unReadCount > 0 || item.unReadCount == '99+'">{{ item.unReadCount
			              }}</view>

										<image :src="
			                item.chatType == 'groupchat' ||
			                  item.chatType == 'chatRoom'
			                  ? 'https://rsyl.oss-cn-beijing.aliyuncs.com/99831a51d7b6443c8e15ee4d23a61bd5.png'
			                  : item.visibleImg||'https://rsyl.oss-cn-beijing.aliyuncs.com/1b315030ef4c47ba82f5a7a1d20c8c4d.png'
			              "></image>
									</view>
									<view class="list_text">
										<text class="list_user">{{
			                  item.chatType == "groupchat" ||
			                    item.chatType == "chatRoom" ||
			                    item.groupName
			                    ? item.groupName
			                    : item.visibleName||item.username
			              }}</text>
										<text class="list_word" v-if="item.msg.data[0].data">{{
			                  item.msg.data[0].data
			              }}</text>
										<text class="list_word" v-if="item.msg.type == 'img'">[图片]</text>
										<text class="list_word" v-if="item.msg.type == 'audio'">[语音]</text>
										<!-- <text class="list_word" v-if="item.msg.type == 'video'"
			                >[视频]</text
			              > -->
									</view>
								</view>
								<view class="list_right">
									<text :data-username="item.username">{{ item.time }}</text>
								</view>
							</view>
						</view>
					</swipe-delete>
				</view>

				<long-press-modal :winSize="winSize" :popButton="popButton" @change="pickerMenuChange"
					:showPop="showPop" @hidePop="hidePop" :popStyle="popStyle" />
				<view v-if="arr.length == 0" class="chat_noChat">
					<image class="ctbg"
						src="https://rsyl.oss-cn-beijing.aliyuncs.com/ec4344d75dd1485e8ff9be9ea7a9ff90.png"></image>
					暂无聊天消息
				</view>
				<!-- </view> -->
			</scroll-view>
			<!-- bug: margin-bottom 不生效 需要加一个空标签-->
			<view style="height: 1px"></view>

		</div>
	</view>
</template>

<script>
	import swipeDelete from "@/components/swipedelete/swipedelete";
	import longPressModal from "@/components/longPressModal/index";
	import storage from "@/utils/storage.js";
	import * as API_Members from "@/api/members.js";
	let isfirstTime = true;
	let WebIM = require("@/utils/WebIM")["default"];
	let disp = require("@/utils/broadcast");
	export default {
		data() {
			return {
				search_btn: true,
				search_chats: false,
				show_mask: false,
				yourname: "",
				unReadSpotNum: 0,
				unReadNoticeNum: 0,
				messageNum: 0,
				unReadTotalNotNum: 0,
				arr: [],
				arrNew: null,
				show_clear: false,
				member: "",
				isIPX: false,
				gotop: false,
				input_code: "",

				groupName: {},
				winSize: {},
				popButton: ["删除该聊天"],
				showPop: false,
				popStyle: "",
				currentVal: '',
				userInfo: null
			}
		},
		components: {
			swipeDelete,
			longPressModal,
		},
		onLoad() {
			console.log(this.userInfo, "开始登录111")
			if (this.$options.filters.isLogin('auth')) {
				this.userInfo = storage.getUserInfo()
				// 登录环信
				this.loginHX()
				this.getWindowSize();
				let me = this;
				disp.on("em.error.passwordErr", function() {
					console.log("开始注册")
					me.register()
					// uni.showToast({
					// 	title: "用户名或密码错误",
					// 	icon: 'none'
					// });
				});
				//监听加好友申请
				disp.on("em.subscribe", function() {
					me.getChatList();
					// me.setData({
					me.me.messageNum = getApp().globalData.saveFriendList.length
					me.unReadTotalNotNum = getApp().globalData.saveFriendList.length +
						getApp().globalData.saveGroupInvitedList.length
					// });
				});

				//监听解散群
				disp.on("em.invite.deleteGroup", function(infos) {
					me.listGroups();
					me.getRoster();
					me.getChatList();
					// me.setData({
					// arr: me.getChatList(),
					me.messageNum = getApp().globalData.saveFriendList.length
					// });
					//如果会话存在则执行删除会话
					me.removeLocalStorage(infos.gid)
				});

				//监听未读消息数
				disp.on("em.unreadspot", function(message) {
					me.getChatList();
					// me.setData({
					// arr: me.getChatList(),
					me.unReadSpotNum = getApp().globalData.unReadMessageNum > 99 ?
						"99+" : getApp().globalData.unReadMessageNum

					// });
				});

				//监听未读加群“通知”
				disp.on("em.invite.joingroup", function() {
					// me.setData({
					me.unReadNoticeNum = getApp().globalData.saveGroupInvitedList.length
					me.unReadTotalNotNum = getApp().globalData.saveFriendList.length +
						getApp().globalData.saveGroupInvitedList.length
					// });
				});

				disp.on("em.contacts.remove", function() {
					me.getChatList();
					me.getRoster();
				});

				this.getRoster();
			} else {
				this.$options.filters.navigateToLogin()
			}

		},
		onShow() {
			if (this.$options.filters.isLogin('auth')) {
				this.userInfo = storage.getUserInfo()
				// 登录环信
				this.loginHX()
				this.getWindowSize();
				let me = this;
				disp.on("em.error.passwordErr", function() {
					console.log("开始注册")
					me.register()
					// uni.showToast({
					// 	title: "用户名或密码错误",
					// 	icon: 'none'
					// });
				});
				//监听加好友申请
				disp.on("em.subscribe", function() {
					me.getChatList();
					// me.setData({
					me.me.messageNum = getApp().globalData.saveFriendList.length
					me.unReadTotalNotNum = getApp().globalData.saveFriendList.length +
						getApp().globalData.saveGroupInvitedList.length
					// });
				});

				//监听解散群
				disp.on("em.invite.deleteGroup", function(infos) {
					me.listGroups();
					me.getRoster();
					me.getChatList();
					// me.setData({
					// arr: me.getChatList(),
					me.messageNum = getApp().globalData.saveFriendList.length
					// });
					//如果会话存在则执行删除会话
					me.removeLocalStorage(infos.gid)
				});

				//监听未读消息数
				disp.on("em.unreadspot", function(message) {
					me.getChatList();
					// me.setData({
					// arr: me.getChatList(),
					me.unReadSpotNum = getApp().globalData.unReadMessageNum > 99 ?
						"99+" : getApp().globalData.unReadMessageNum

					// });
				});

				//监听未读加群“通知”
				disp.on("em.invite.joingroup", function() {
					// me.setData({
					me.unReadNoticeNum = getApp().globalData.saveGroupInvitedList.length
					me.unReadTotalNotNum = getApp().globalData.saveFriendList.length +
						getApp().globalData.saveGroupInvitedList.length
					// });
				});

				disp.on("em.contacts.remove", function() {
					me.getChatList();
					me.getRoster();
				});

				this.getRoster();
			}
			uni.hideHomeButton();
			this.getChatList();
			// this.setData({
			//arr: this.getChatList(),
			this.unReadSpotNum = getApp().globalData.unReadMessageNum > 99 ?
				"99+" : getApp().globalData.unReadMessageNum
			this.messageNum = getApp().globalData.saveFriendList.length
			this.unReadNoticeNum = getApp().globalData.saveGroupInvitedList.length
			this.unReadTotalNotNum = getApp().globalData.saveFriendList.length +
				getApp().globalData.saveGroupInvitedList.length
			// });

			if (getApp().globalData.isIPX) {
				// this.setData({
				this.isIPX = true
				// });
			}
		},
		methods: {
			loginHX() {
				// console.log(111, {
				//     apiUrl: WebIM.config.apiURL,
				//     user: __test_account__ || this.name.toLowerCase(),
				//     pwd: __test_psword__ || this.psd,
				//     grant_type: this.grant_type,
				//     appKey: WebIM.config.appkey
				//   })

				uni.setStorage({
					key: "myUsername",
					data: this.userInfo.id
				});
				console.log(this.userInfo, "开始登录")
				uni.WebIM.conn.open({
					apiUrl: WebIM.config.apiURL,
					// user: "123333333",
					// pwd: "123333333",
					user: this.userInfo.id,
					pwd: this.userInfo.id,
					grant_type: "password",
					appKey: WebIM.config.appkey
				});
				// uni.redirectTo({
				// 	url: "../chat/chat?myName=" + myName,
				// });
			},
			register: function() {
				const that = this;

				var options = {
					apiUrl: WebIM.config.apiURL,
					username: this.userInfo.id,
					password: this.userInfo.id,
					nickname: this.userInfo.nickName,
					appKey: WebIM.config.appkey,
					success: function(res) {
						// uni.showToast({title: "注册成功"});
						that.loginHX()
						// var data = {
						//   apiUrl: WebIM.config.apiURL,
						//   user: that.username.toLowerCase(),
						//   pwd: that.password,
						//   grant_type: "password",
						//   appKey: WebIM.config.appkey
						// };
						// uni.setStorage({
						//   key: "myUsername",
						//   data: that.username
						// });
					},
					error: function(res) {

						if (res.statusCode !== "200") {
							// if (res.statusCode == '400' && res.data.error == 'illegal_argument') {
							// 	return uni.showToast({
							// 		title: "用户名非法",
							// 		icon: 'none'
							// 	});
							// }

							// uni.showToast({
							// 	title: "用户名已被占用",
							// 	icon: 'none'
							// });
						}
					}
				};
				WebIM.conn.registerUser(options);
			},
			listGroups() {
				var me = this;
				return WebIM.conn.getGroup({
					limit: 50,
					success: function(res) {
						let groupName = {};
						let listGroup = res.data || [];
						listGroup.forEach((item) => {
							groupName[item.groupid] = item.groupname;
						});

						// me.setData({
						me.groupName = groupName
						// });
						uni.setStorage({
							key: "listGroup",
							data: res.data,
						});
						me.getChatList();
					},
					error: function(err) {
						console.log(err);
					},
				});
			},

			getRoster() {
				let me = this;
				let rosters = {
					success(roster) {
						var member = [];
						for (let i = 0; i < roster.length; i++) {
							if (roster[i].subscription == "both") {
								member.push(roster[i]);
							}
						}
						uni.setStorage({
							key: "member",
							data: member,
						});
						// me.setData({
						me.member = member
						// });
						me.listGroups();
						//if(!systemReady){
						disp.fire("em.main.ready");
						//systemReady = true;
						//}
						// me.setData({
						me.arr = me.getChatList()
						me.unReadSpotNum = getApp().globalData.unReadMessageNum > 99 ?
							"99+" : getApp().globalData.unReadMessageNum
						// });
					},
					error(err) {
						console.log(err);
					},
				};
				WebIM.conn.getRoster(rosters);
			},

			// // 不包含陌生人版本
			// getChatList() {
			//   var array = [];
			//   var member = uni.getStorageSync("member");
			//   var myName = uni.getStorageSync("myUsername");
			//   var listGroups = uni.getStorageSync('listGroup') || [];

			//   for (let i = 0; i < member.length; i++) {
			//     let newChatMsgs = uni.getStorageSync(member[i].name + myName) || [];
			//     let historyChatMsgs = uni.getStorageSync("rendered_" + member[i].name + myName) || [];
			//     let curChatMsgs = historyChatMsgs.concat(newChatMsgs);

			//     if (curChatMsgs.length) {
			//       let lastChatMsg = curChatMsgs[curChatMsgs.length - 1];
			//       lastChatMsg.unReadCount = newChatMsgs.length;

			//       if (lastChatMsg.unReadCount > 99) {
			//         lastChatMsg.unReadCount = "99+";
			//       }

			//       let dateArr = lastChatMsg.time.split(' ')[0].split('-');
			//       let timeArr = lastChatMsg.time.split(' ')[1].split(':');
			//       let month = dateArr[2] < 10 ? '0' + dateArr[2] : dateArr[2];
			//       lastChatMsg.dateTimeNum = `${dateArr[1]}${month}${timeArr[0]}${timeArr[1]}${timeArr[2]}`;
			//       lastChatMsg.time = `${dateArr[1]}月${dateArr[2]}日 ${timeArr[0]}:${timeArr[1]}`;
			//       array.push(lastChatMsg);
			//     }
			//   }

			//   for(let i = 0; i < listGroups.length; i++){
			//  let newChatMsgs = uni.getStorageSync(listGroups[i].groupid + myName) || [];
			//  let historyChatMsgs = uni.getStorageSync("rendered_" + listGroups[i].groupid + myName) || [];
			//  let curChatMsgs = historyChatMsgs.concat(newChatMsgs);
			//  if(curChatMsgs.length){
			//    let lastChatMsg = curChatMsgs[curChatMsgs.length - 1];
			//    lastChatMsg.unReadCount = newChatMsgs.length;
			//    if(lastChatMsg.unReadCount > 99) {
			//      lastChatMsg.unReadCount = "99+";
			//    }
			//    let dateArr = lastChatMsg.time.split(' ')[0].split('-')
			//    let timeArr = lastChatMsg.time.split(' ')[1].split(':')
			//    let month = dateArr[2] < 10 ? '0' + dateArr[2] : dateArr[2]
			//    lastChatMsg.time = `${dateArr[1]}月${dateArr[2]}日 ${timeArr[0]}:${timeArr[1]}`
			//    lastChatMsg.dateTimeNum = `${dateArr[1]}${month}${timeArr[0]}${timeArr[1]}${timeArr[2]}`
			//    lastChatMsg.groupName = listGroups[i].groupname
			//    array.push(lastChatMsg);
			//  }
			// }

			//   array.sort((a, b) => {
			//     return b.dateTimeNum - a.dateTimeNum;
			//   });
			//   return array;
			// },

			// 包含陌生人版本
			getChatList() {
				var myName = uni.getStorageSync("myUsername");
				var array = [];
				const me = this;
				uni.getStorageInfo({
					success: function(res) {
						let storageKeys = res.keys;
						let newChatMsgKeys = [];
						let historyChatMsgKeys = [];
						let len = myName.length;
						storageKeys.forEach((item) => {
							if (item.indexOf(myName) >= 0 && item.indexOf("rendered_") == -1) {
								newChatMsgKeys.push(item);
							} else if (
								item.indexOf(myName) >= 0 &&
								item.indexOf("rendered_") > -1
							) {
								historyChatMsgKeys.push(item);
							} else if (item === "INFORM") {
								newChatMsgKeys.push(item);
							}
						});
						cul.call(me, newChatMsgKeys, historyChatMsgKeys);
					},
				});

				function cul(newChatMsgKeys, historyChatMsgKeys) {
					let array = [];
					let lastChatMsg;

					for (let i = historyChatMsgKeys.length; i > 0, i--;) {
						let index = newChatMsgKeys.indexOf(historyChatMsgKeys[i].slice(9));
						if (index > -1) {
							let newChatMsgs = uni.getStorageSync(newChatMsgKeys[index]) || [];
							if (newChatMsgKeys.includes()) {}
							if (newChatMsgs.length) {
								lastChatMsg = newChatMsgs[newChatMsgs.length - 1];
								lastChatMsg.unReadCount = newChatMsgs.length;
								if (lastChatMsg.unReadCount > 99) {
									lastChatMsg.unReadCount = "99+";
								}
								let dateArr = lastChatMsg.time.split(" ")[0].split("-");
								let timeArr = lastChatMsg.time.split(" ")[1].split(":");
								let month = dateArr[2] < 10 ? "0" + dateArr[2] : dateArr[2];
								lastChatMsg.dateTimeNum = `${dateArr[1]}${month}${timeArr[0]}${timeArr[1]}${timeArr[2]}`;
								lastChatMsg.time = `${dateArr[1]}月${dateArr[2]}日 ${timeArr[0]}:${timeArr[1]}`;
								newChatMsgKeys.splice(index, 1);
							} else {
								let historyChatMsgs = uni.getStorageSync(historyChatMsgKeys[i]);
								if (historyChatMsgs.length) {
									lastChatMsg = historyChatMsgs[historyChatMsgs.length - 1];
									let dateArr = lastChatMsg.time.split(" ")[0].split("-");
									let timeArr = lastChatMsg.time.split(" ")[1].split(":");
									let month = dateArr[2] < 10 ? "0" + dateArr[2] : dateArr[2];
									lastChatMsg.dateTimeNum =
										`${dateArr[1]}${month}${timeArr[0]}${timeArr[1]}${timeArr[2]}`;
									lastChatMsg.time = `${dateArr[1]}月${dateArr[2]}日 ${timeArr[0]}:${timeArr[1]}`;
								}
							}
						} else {
							let historyChatMsgs = uni.getStorageSync(historyChatMsgKeys[i]);
							if (historyChatMsgs.length) {
								lastChatMsg = historyChatMsgs[historyChatMsgs.length - 1];
								let dateArr = lastChatMsg.time.split(" ")[0].split("-");
								let timeArr = lastChatMsg.time.split(" ")[1].split(":");
								let month = dateArr[2] < 10 ? "0" + dateArr[2] : dateArr[2];
								lastChatMsg.dateTimeNum = `${dateArr[1]}${month}${timeArr[0]}${timeArr[1]}${timeArr[2]}`;
								lastChatMsg.time = `${dateArr[1]}月${dateArr[2]}日 ${timeArr[0]}:${timeArr[1]}`;
							}
						}
						if (
							lastChatMsg &&
							(lastChatMsg.chatType == "groupchat" ||
								lastChatMsg.chatType == "chatRoom")
						) {
							lastChatMsg.groupName = me.groupName[lastChatMsg.info.to];
						}
						lastChatMsg && lastChatMsg.username != myName &&
							array.push(lastChatMsg);
					}

					for (let i = newChatMsgKeys.length; i > 0, i--;) {
						let newChatMsgs = uni.getStorageSync(newChatMsgKeys[i]) || [];
						if (newChatMsgs.length) {
							lastChatMsg = newChatMsgs[newChatMsgs.length - 1];
							lastChatMsg.unReadCount = newChatMsgs.length;
							if (lastChatMsg.unReadCount > 99) {
								lastChatMsg.unReadCount = "99+";
							}
							let dateArr = lastChatMsg.time.split(" ")[0].split("-");
							let timeArr = lastChatMsg.time.split(" ")[1].split(":");
							let month = dateArr[2] < 10 ? "0" + dateArr[2] : dateArr[2];
							lastChatMsg.dateTimeNum = `${dateArr[1]}${month}${timeArr[0]}${timeArr[1]}${timeArr[2]}`;
							lastChatMsg.time = `${dateArr[1]}月${dateArr[2]}日 ${timeArr[0]}:${timeArr[1]}`;
							if (
								lastChatMsg.chatType == "groupchat" ||
								lastChatMsg.chatType == "chatRoom"
							) {
								lastChatMsg.groupName = me.groupName[lastChatMsg.info.to];
							}
							lastChatMsg.username != myName && array.push(lastChatMsg);
						}
					}

					array.sort((a, b) => {
						return b.dateTimeNum - a.dateTimeNum;
					});
					// this.setData({
					console.log(array, "加载数据")
					// this.arr = array
					this.getArrName(array)
					// });
				}
			},
			getArrName(array) {
				API_Members.getUserInfoById({
					memberIds: array.map(item => item.username).toString()
				}).then(res => {
					if (res.data.success && res.data.result && res.data.result.length > 0) {
						array.forEach(item => {
							let Obj = res.data.result.find(ele => ele.id == item.username)
							if (Obj) {
								uni.getStorageInfo({
									success: (res1) => {
										let storageKeys = res1.keys;
										let key = storageKeys.find(key => key.indexOf(item
											.username) >= 0 && key.indexOf(
											"rendered_") < 0)
										if (key) {
											if (key.indexOf(item.username) == 0) {
												this.$set(item, "visibleName", Obj.nickName)
												this.$set(item, "visibleImg", Obj.face)
											} else {
												if (Obj.storeId) {
													this.$set(item, "visibleName", Obj
														.storeName)
													this.$set(item, "visibleImg", Obj
														.storeLogo)
												} else {
													this.$set(item, "visibleName", Obj
														.nickName)
													this.$set(item, "visibleImg", Obj.face)
												}
											}
										}
									},
								})
							}
						})
						setTimeout(() => {
							this.arr = [].concat(array)
						}, 0)
					}
				})
			},
			openSearch(searchStr) {
				// this.pageNum = 1;
				if (searchStr) {
					this.arrNew = this.arr.filter(item => {
						return (item.visibleName && item.visibleName.indexOf(searchStr) >= 0) || (item.userName &&
							item.userName.indexOf(searchStr) >= 0)
					})
				} else {
					this.arrNew = null
				}
				// this.setData({
				// this.search_btn = false
				// this.search_chats = true
				// this.gotop = true
				// });
			},

			onSearch: function(val) {
				let searchValue = val.detail.value;
				var myName = uni.getStorageSync("myUsername");
				const me = this;
				let serchList = [];
				let arr = [];
				uni.getStorageInfo({
					success: function(res) {
						let storageKeys = res.keys;
						let chatKeys = [];
						let len = myName.length;
						storageKeys.forEach((item) => {
							if (item.indexOf(myName) >= 0) {
								chatKeys.push(item);
							}
						});
						chatKeys.forEach((item, index) => {
							if (item.indexOf(searchValue) != -1) {
								serchList.push(item);
							}
						});
						let lastChatMsg = "";
						serchList.forEach((item, index) => {
							let chatMsgs = uni.getStorageSync(item) || [];
							if (chatMsgs.length) {
								lastChatMsg = chatMsgs[chatMsgs.length - 1];

								let dateArr = lastChatMsg.time.split(" ")[0].split("-");
								let timeArr = lastChatMsg.time.split(" ")[1].split(":");
								let month = dateArr[2] < 10 ? "0" + dateArr[2] : dateArr[2];
								lastChatMsg.dateTimeNum =
									`${dateArr[1]}${month}${timeArr[0]}${timeArr[1]}${timeArr[2]}`;
								lastChatMsg.time =
									`${dateArr[1]}月${dateArr[2]}日 ${timeArr[0]}:${timeArr[1]}`;
								arr.push(lastChatMsg);
							}
						});
						// me.setData({
						// me.arr = arr
						me.getArrName(arr)
						// });
					},
				});
			},

			cancel: function() {
				this.getChatList();
				// this.setData({
				this.search_btn = true
				this.search_chats = false
				//arr: this.getChatList()
				this.unReadSpotNum = getApp().globalData.unReadMessageNum > 99 ?
					"99+" : getApp().globalData.unReadMessageNum
				this.gotop = false
				// });
			},
			clearInput: function() {
				// this.setData({
				this.input_code = ""
				this.show_clear = false
				// });
			},
			onInput: function(e) {
				let inputValue = e.detail.value;
				if (inputValue) {
					// this.setData({
					this.show_clear = true
					// });
				} else {
					// this.setData({
					this.show_clear = false
					// });
				}
			},
			tab_contacts: function() {
				uni.redirectTo({
					url: "../main/main?myName=" + uni.getStorageSync("myUsername"),
				});
			},
			close_mask: function() {
				// this.setData({
				this.search_btn = true
				this.search_chats = false
				this.show_mask = false
				// });
			},
			tab_setting: function() {
				uni.redirectTo({
					url: "../setting/setting",
				});
			},
			into_chatRoom: function(event) {
				let detail = event.currentTarget.dataset.item;
				if (
					detail.chatType == "groupchat" ||
					detail.chatType == "chatRoom" ||
					detail.groupName
				) {
					this.into_groupChatRoom(detail);
				} else {
					this.into_singleChatRoom(detail);
				}
			},
			// 单聊
			into_singleChatRoom: function(detail) {
				console.log(detail, "用户信息")
				var my = uni.getStorageSync("myUsername");
				var nameList = {
					myName: my,
					your: detail.username,
					nickName: detail.visibleName || detail.username
				};
				console.log(nameList, "打开对话窗口")
				uni.navigateTo({
					url: "../../chatroom/chatroom?username=" + JSON.stringify(nameList),
				});
			},
			// 群聊 和 聊天室 （两个概念）
			into_groupChatRoom: function(detail) {
				var my = uni.getStorageSync("myUsername");
				var nameList = {
					myName: my,
					your: detail.groupName,
					groupId: detail.info.to,
				};
				uni.navigateTo({
					url: "../groupChatRoom/groupChatRoom?username=" + JSON.stringify(nameList),
				});
			},

			into_inform: function() {
				uni.redirectTo({
					url: "./notification/notification",
				});
			},

			removeAndRefresh: function(event) {
				let removeId = event.currentTarget.dataset.item.info.from
				let ary = getApp().globalData.saveFriendList
				let idx
				if (ary.length > 0) {
					ary.forEach((v, k) => {
						if (v.from == removeId) {
							idx = k
						}
					})
					getApp().globalData.saveFriendList.splice(idx, 1);
				}
				uni.removeStorageSync('INFORM')
			},

			del_chat: function(event) {
				console.log('>>>>>>>>删除会话列表', event)
				let detail = event.currentTarget.dataset.item;
				let nameList = {};
				let me = this;
				// 删除当前选中群组聊天列表
				if (detail.chatType == "groupchat" || detail.chatType == "chatRoom") {
					nameList = {
						your: detail.info.to,
					};
					//删除当前选中通知列表
				} else if (detail.chatType === "INFORM") {
					nameList = {
						your: "INFORM",
					};
				}
				//删除当前选中好友聊天列表
				else {
					nameList = {
						your: detail.username,
					};
				}
				var myName = uni.getStorageSync("myUsername");
				var currentPage = getCurrentPages();

				uni.showModal({
					title: "确认删除？",
					confirmText: "删除",
					success: function(res) {
						if (res.confirm) {
							uni.removeStorageSync(nameList.your + myName);
							uni.removeStorageSync(myName + nameList.your);
							uni.removeStorageSync("rendered_" + nameList.your + myName);
							uni.removeStorageSync("rendered_" + myName + nameList.your);
							nameList.your === 'INFORM' && me.removeAndRefresh(event);
							// if (Object.keys(currentPage[0]).length>0) {
							//   currentPage[0].onShow();
							// }
							disp.fire("em.chat.session.remove");
							me.getChatList();
						}
					},
					fail: function(err) {
						console.log('删除列表', err);
					},
				});
			},
			removeLocalStorage: function(yourname) {
				console.log('>>>>>>>>执行删除本地会话')
				var myName = uni.getStorageSync("myUsername");
				uni.removeStorageSync(yourname + myName);
				uni.removeStorageSync(myName + yourname);
				uni.removeStorageSync("rendered_" + myName + yourname);
				uni.removeStorageSync("rendered_" + myName + yourname);
			},
			longpress: function(e) {
				//将当前选中的值存在data中方便后续操作
				this.currentVal = e
				let [touches, style, index] = [e.touches[0], "", e.currentTarget.dataset.index, ];

				/* 因 非H5端不兼容 style 属性绑定 Object ，所以拼接字符 */
				if (touches.clientY > this.winSize.height / 2) {
					style = `bottom:${this.winSize.height - touches.clientY}px;`;
				} else {
					style = `top:${touches.clientY}px;`;
				}
				if (touches.clientX > this.winSize.witdh / 2) {
					style += `right:${this.winSize.witdh - touches.clientX}px`;
				} else {
					style += `left:${touches.clientX}px`;
				}

				this.popStyle = style;
				// this.pickerUserIndex = Number(index);
				this.showShade = true;
				this.$nextTick(() => {
					setTimeout(() => {
						this.showPop = true;
					}, 10);
				});
			},
			/* 获取窗口尺寸 */
			getWindowSize() {
				uni.getSystemInfo({
					success: (res) => {
						this.winSize = {
							witdh: res.windowWidth,
							height: res.windowHeight,
						};
					},
				});
			},
			hidePop() {
				this.showPop = false;
			},
			pickerMenuChange() {
				console.log("当前选中>>", this.currentVal);
				this.del_chat(this.currentVal)
			},

			toNoticeList() {
				uni.navigateTo({
					url: '/pages/message/notice'
				})
			},

		}
	}
</script>

<style>
	@import "./chat.css";
</style>
<style lang="scss">
	.message-notice-wrapper {
		.list-wrapper {
			margin-top: 24upx;
			background-color: #ffffff;

			.more-search {
				padding: 20rpx;
			}

			.item-wrapper {
				display: flex;
				height: 112upx;
				align-items: center;
				justify-content: space-between;
				padding: 0 32upx;
				margin-top: 10upx;
				background-color: #fff;

				.systemInform {
					display: flex;

					.image {
						margin-right: 16upx;
						width: 88upx;
						height: 88upx;
					}

					.text {
						.name {
							font-size: 30upx;
							margin-bottom: 10upx;
						}

						.newInformation {
							font-size: 28upx;
							color: rgba(141, 141, 141, 1);
						}
					}
				}

				.item {
					text-align: center;

					.time {
						font-size: 22rpx;
						color: rgba(201, 201, 201, 1);
						margin-bottom: 10upx;
					}

					.itemNumber {
						background-color: rgba(230, 50, 20, 1);
						border-radius: 22upx;
						text-align: center;
						color: rgba(255, 255, 255, 1);
						font-size: 22rpx;
						padding: 0 10upx;
					}
				}
			}
		}
	}
</style>
